<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */
$basedir = dirname(__FILE__);
require_once $basedir . '/../../../../classes/minime/pubsubhubbub/subscribers.php';
require_once $basedir . '/../../../../classes/minime/pubsubhubbub/subscriber.php';

class Minime_Pubsubhubbub_SubscribersTest extends PHPUnit_Framework_TestCase {
    
    public function testRemoveSubscriber() {
        $rawXML = '<?xml version="1.0" encoding="UTF-8"?>
<pubsubhubbub_subscribers>
  <pubsubhubbub_subscriber id="a9a1819b0ab148eff45100d3bbfdbbd6">
    <callback>http://callback.com/callback.php</callback>
    <topic>http://identi.ca/api/statuses/user_timeline/209172.atom</topic>
    <lease_seconds>60</lease_seconds>
    <secret>SECRETQSDF345SDRT35ERG35SDFG35SRG</secret>
    <verify_token>4887bdf3f67a025e2b0a622b7f19de85</verify_token>
    <title>This is the topic of the followed node.</title>
    <subid>a9a1819b0ab148eff45100d3bbfdbbd6</subid>
  </pubsubhubbub_subscriber>
  <pubsubhubbub_subscriber id="bbaabb19b0ab148eff45100d3bbfdbbd6">
    <callback>http://thecallback.com/callback.php</callback>
    <topic>http://theidenti.ca/api/statuses/user_timeline/209172.atom</topic>
    <lease_seconds>90</lease_seconds>
    <secret>SECRET_A_BIG_ONE</secret>
    <verify_token>4887bdf3f67a025e2b0a622b7f19de85</verify_token>
    <title>This is the topic of the followed Another node.</title>
    <subid>bbaabb19b0ab148eff45100d3bbfdbbd6</subid>
  </pubsubhubbub_subscriber>
</pubsubhubbub_subscribers>
';
        
        $dev = Minime_Pubsubhubbub_Subscribers::buildFromRawXML($rawXML);
        $this->assertEquals($rawXML, $dev->asXML());
        $dev->removeSubscriber("bbaabb19b0ab148eff45100d3bbfdbbd6");
        
        $expected = '<?xml version="1.0" encoding="UTF-8"?>
<pubsubhubbub_subscribers>
  <pubsubhubbub_subscriber id="a9a1819b0ab148eff45100d3bbfdbbd6">
    <callback>http://callback.com/callback.php</callback>
    <topic>http://identi.ca/api/statuses/user_timeline/209172.atom</topic>
    <lease_seconds>60</lease_seconds>
    <secret>SECRETQSDF345SDRT35ERG35SDFG35SRG</secret>
    <verify_token>4887bdf3f67a025e2b0a622b7f19de85</verify_token>
    <title>This is the topic of the followed node.</title>
    <subid>a9a1819b0ab148eff45100d3bbfdbbd6</subid>
  </pubsubhubbub_subscriber>
</pubsubhubbub_subscribers>
';
        $this->assertEquals($expected, $dev->asXML());
    }
    
}